home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / unicharutil / nsUnicharUtils.h < prev   
C/C++ Source or Header  |  2006-05-08  |  5KB  |  112 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is Unicode case conversion helpers.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corp..
  19.  * Portions created by the Initial Developer are Copyright (C) 2002
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Alec Flett <alecf@netscape.com>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. #ifndef nsUnicharUtils_h__
  40. #define nsUnicharUtils_h__
  41. #ifndef nsAString_h___
  42. #include "nsAString.h"
  43. #endif
  44. #include "nsReadableUtils.h"
  45.  
  46. void ToLowerCase( nsAString& );
  47. void ToUpperCase( nsAString& );
  48.  
  49. void ToLowerCase( nsASingleFragmentString& );
  50. void ToUpperCase( nsASingleFragmentString& );
  51.  
  52. void ToLowerCase( nsString& );
  53. void ToUpperCase( nsString& );
  54.  
  55. void ToLowerCase( const nsAString& aSource, nsAString& aDest );
  56. void ToUpperCase( const nsAString& aSource, nsAString& aDest );
  57.  
  58. class nsCaseInsensitiveStringComparator
  59.     : public nsStringComparator
  60.   {
  61.     public:
  62.       virtual int operator()( const PRUnichar*, const PRUnichar*, PRUint32 aLength ) const;
  63.       virtual int operator()( PRUnichar, PRUnichar ) const;
  64.   };
  65.  
  66. inline PRBool CaseInsensitiveFindInReadable( const nsAString& aPattern,
  67.                                              nsAString::const_iterator& aSearchStart,
  68.                                              nsAString::const_iterator& aSearchEnd ) {
  69.   return FindInReadable(aPattern, aSearchStart, aSearchEnd,
  70.                         nsCaseInsensitiveStringComparator());
  71. }
  72.  
  73. inline PRBool CaseInsensitiveFindInReadable( const nsAString& aPattern,
  74.                                              const nsAString& aHay ) {
  75.   nsAString::const_iterator searchBegin, searchEnd;
  76.   return FindInReadable(aPattern, 
  77.                         aHay.BeginReading(searchBegin),
  78.                         aHay.EndReading(searchEnd),
  79.                         nsCaseInsensitiveStringComparator());
  80. }
  81.  
  82. PRUnichar ToUpperCase(PRUnichar);
  83. PRUnichar ToLowerCase(PRUnichar);
  84.  
  85. inline PRBool IsUpperCase(PRUnichar c) {
  86.     return ToLowerCase(c) != c;
  87. }
  88.  
  89. inline PRBool IsLowerCase(PRUnichar c) {
  90.     return ToUpperCase(c) != c;
  91. }
  92.  
  93. #define IS_HIGH_SURROGATE(u)  ((PRUnichar)(u) >= (PRUnichar)0xd800 && (PRUnichar)(u) <= (PRUnichar)0xdbff)
  94. #define IS_LOW_SURROGATE(u)  ((PRUnichar)(u) >= (PRUnichar)0xdc00 && (PRUnichar)(u) <= (PRUnichar)0xdfff)
  95.  
  96. #define SURROGATE_TO_UCS4(h, l)  ((((PRUint32)(h)-(PRUint32)0xd800) << 10) +  \
  97.                                     (PRUint32)(l) - (PRUint32)(0xdc00) + 0x10000)
  98.  
  99. #define H_SURROGATE(s) ((PRUnichar)(((PRUint32)s - (PRUint32)0x10000) >> 10) + (PRUnichar)0xd800)
  100. #define L_SURROGATE(s) ((PRUnichar)(((PRUint32)s - (PRUint32)0x10000) & 0x3ff) + (PRUnichar)0xdc00)
  101. #define IS_IN_BMP(ucs) ((PRUint32)ucs < 0x10000)
  102.  
  103. /* (0x3131u <= (u) && (u) <= 0x318eu) => Hangul Compatibility Jamo */
  104. /* (0xac00u <= (u) && (u) <= 0xd7a3u) => Hangul Syllables          */
  105. #define IS_CJ_CHAR(u) \
  106.          ((0x2e80u <= (u) && (u) <= 0x312fu) || \
  107.           (0x3190u <= (u) && (u) <= 0xabffu) || \
  108.           (0xf900u <= (u) && (u) <= 0xfaffu) || \
  109.           (0xff00u <= (u) && (u) <= 0xffefu) )
  110.  
  111. #endif  /* nsUnicharUtils_h__ */
  112.